<?php require './view/public/header.php'; ?>
    <!--/sidebar-->
    <div class="main-wrap">
        <div class="search-wrap">
            <div class="search-content">
                <form action="./index.php">
				<input type="hidden" name="c" value="goods" />
				<input type="hidden" name="a" value="index" />
                    <table class="search-tab">
                        <tr>
                            <th width="120">选择分类:</th>
                            <td>
                                <select name="tid" id="">
                                    <option value='-1'>全部</option>
                                   <?php
										if(!isset($_GET['tid'])) $_GET['tid']='';
										foreach($arr as $k=>$v){
											if($_GET['tid']==$k) $s='selected'; else $s='';
											echo "<option $s value='$k'>$v</option>";
										}
								   ?>
                                </select>
                            </td>
                            <th width="70">关键字:</th>
                            <td><input class="common-text" placeholder="名字" name="gname" value="<?php if(isset($_GET['gname'])) echo $_GET['gname']; ?>" id="" type="text"></td>
                            <td><input class="btn btn-primary btn2" value="查询" type="submit"></td>
                        </tr>
                    </table>
                </form>
            </div>
        </div>
        <div class="result-wrap">
            <form name="myform" id="myform" method="post">
                <div class="result-content">
                    <table class="result-tab" width="100%">
                        <tr>
                            <th>商品ID</th>
                            <th>商品名称</th>
                            <th>商品类别</th>
                            <th>价格</th>
                            <th>库存</th>
                            <th>销量</th>
                            <th>浏览量</th>
                            <th>商品图片</th>
                            <th>商品描述</th>
                            <th>状态</th>
                            <th>上次修改时间</th>
                            <th>操作</th>
                        </tr>
						<?php
							if(!isset($_GET['gname'])){
								$_GET['gname']='';
								$_GET['tid']='';
							}
							if(!$ret)die;
							$status = ['下架','上架'];
							foreach($ret as $v){
								echo '<tr>';
									echo '<td>'.$v['gid'].'</td>';
									echo '<td>'.$v['gname'].'</td>';
									echo '<td>'.$arr[$v['tid']].'</td>';
									echo '<td style="color:deeppink">'.$v['price'].'</td>';
									echo '<td>'.$v['cnt'].'</td>';
									echo '<td>'.$v['scnt'].'</td>';
									echo '<td>'.$v['vcnt'].'</td>';
									echo '<td><img width="222" src="'.PIC_PATH.'sm_'.$v['gpic'].'"></td>';
									echo '<td width="200" style="line-height:20px;">'.$v['gdesc'].'</td>';
									if($v['status']==0){
										echo '<td style="color:green">'.$status[$v['status']].'</td>';
									}elseif($v['status']==1){
										echo '<td style="color:red">'.$status[$v['status']].'</td>';
									}
									echo '<td>'.date('Y-m-d',$v['ctime']).'<br />'.date('H:i:s',$v['ctime']).'</td>';
									echo '<td>';
									echo "<a class='link-update' href='./index.php?c=goods&a=edit&id=$v[gid]&nowPage=$nowPage'>修改</a><br />
										  <a onclick=\"return confirm('确定要删除吗?')\" class='link-del' href='./index.php?c=goods&a=del&pic=$v[gpic]&id=$v[gid]&nowPage=$nowPage'>删除</a><br />";
									if($v['status']==0){
										echo " <a style='color:red' class='link-update' href='./index.php?c=goods&a=status&id=$v[gid]&status=1&nowPage=$nowPage'>上架</a>";
									}elseif($v['status']==1){
										echo " <a style='color:green' class='link-update' href='./index.php?c=goods&a=status&id=$v[gid]&status=0&nowPage=$nowPage'>下架</a>";
									}
									echo '</td>';
									
								echo '</tr>';
							}
						?>
                    </table>
                    <div class="list-page">
						<?php
							echo "<a href='./index.php?c=goods&a=index&nowPage=1'>首页</a>";
							echo "<a href='./index.php?c=goods&a=index&nowPage=$prevPage'>上一页</a>";
							echo " &nbsp; $allRows 条 $nowPage/$allPage 页 &nbsp; ";
							echo "<a href='./index.php?c=goods&a=index&nowPage=$nextPage'>下一页</a>";
							echo "<a href='./index.php?c=goods&a=index&nowPage=$allPage'>尾页</a>";
						?>
					</div>
                </div>
            </form>
        </div>
    </div>
    <!--/main-->
<?php require './view/public/footer.php'; ?>